package com.bsoft.rpc.basic.serialization;

import lombok.Getter;

public enum SerializationType {
    /**
     * hessian
     */
    HESSIAN((byte) 0),
    /**
     * hessian2
     */
    HESSIAN2((byte) 1),
    /**
     * json
     */
    JSON((byte) 2),
    /**
     * kryo
     */
    KRYO((byte) 3),
    /**
     * fst
     */
    FST((byte) 4),
    /**
     * jdk
     */
    JDK((byte) 5),
    /**
     * Protostuff
     */
    PROTOSTUFF((byte) 6),
    ;

    @Getter
    private byte type;

    SerializationType(byte type) {
        this.type = type;
    }

    public static SerializationType parseByName(String typeName) {
        for (SerializationType typeEnum : SerializationType.values()) {
            if (typeEnum.name().equalsIgnoreCase(typeName)) {
                return typeEnum;
            }
        }
        return HESSIAN;
    }

    public static SerializationType parseByType(byte type) {
        for (SerializationType typeEnum : SerializationType.values()) {
            if (typeEnum.getType() == type) {
                return typeEnum;
            }
        }
        return HESSIAN;
    }
}
